package com.xgl.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xgl.mapper.RewardinfoMapper;
import com.xgl.pojo.RespBean;
import com.xgl.pojo.RespPageBean;
import com.xgl.pojo.Rewardinfo;
import com.xgl.pojo.Studentinfo;
import com.xgl.service.IRewardinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 学生获奖信息 服务实现类
 * </p>
 *
 * @author 最最帅气的熊国林
 * @since 2021-05-09
 */
@Service
public class RewardinfoServiceImpl extends ServiceImpl<RewardinfoMapper, Rewardinfo> implements IRewardinfoService {

    @Autowired
    private RewardinfoMapper rewardinfoMapper;
    @Override
    public RespPageBean getRewardinfoByPage(Integer currentPage, Integer size, Rewardinfo rewardinfo, LocalDate[] beginDateScope) {
        //开启分页
        Page<Rewardinfo> page = new Page<>(currentPage, size);
        IPage<Rewardinfo> rewardinfoIPage = rewardinfoMapper.getRewardinfoByPage(page, rewardinfo, beginDateScope);
        RespPageBean respPageBean = new RespPageBean(rewardinfoIPage.getTotal(), rewardinfoIPage.getRecords());
        return respPageBean;
    }

    @Override
    public RespBean addRewardinfo(Rewardinfo rewardinfo) {
        if (rewardinfoMapper.insert(rewardinfo) == 1){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }



    @Override
    public List<Rewardinfo> getRewardInfo(Integer id) {
        return rewardinfoMapper.getRewardInfo(id);
    }

    @Override
    public RespBean insertHashCode(Integer id, String hashCode) {
        if (rewardinfoMapper.insertHashCode(id,hashCode) && rewardinfoMapper.insertPreviousHash(id,hashCode)){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }
}
